<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script type="text/javascript">
    $().ready(function() { 
    	calendar.makeCalender("sStartDate");
        calendar.makeCalender("sEndDate");
    	view(1);  
        var contents = "";
        var cHeader = "<tr>"
            +"<th width='25%'>Stock Out No</th>"
            +"<th width='15%'>Date</th>"
            +"<th width='40%'>Name</th>"
            +"<th width='20%'>Tel</th>"
            +"</tr>";
        contents = "<tr><td colspan='4' height='50' bgcolor='#FFFFFF' align='center'></td></tr>";
        $("#stockOutNoDetail").html(cHeader+contents);
            
        /* 조회버튼 */
        $("#btnSearch").bind("click",function(){       
            view(1);
        }); 

        $("#cancelBtn").bind("click",function(){       
            self.close();
        });  

        $("#confirmBtn").bind("click",function(){   
            var outNo = $("#outNoTmp").val();
            var outInvoice = $("#outInvoiceTmp").val();

            if(outNo==null   || outNo=="") {   alert("Row selected!!"); return false; }

            opener.stockOutNoPopValue(outNo, outInvoice);
            self.close();
        });
        
    });

    function view(page){
        $.post(
                '/getStockOutNoPopView.json', {                      
                paging : page,//odrNo,
                listScale : "5",
               // custDiv : $("#custDiv").val(),
                outInvoice : $("#outInvoice").val(),
                sStartDate : $("#sStartDate").val(),
                sEndDate : $("#sEndDate").val(),
                sMessrs : $("#sMessrs").val(),
                goodsCode : $("#sGoodsCode").val(),
                batchNo : $("#lotNo").val(),
                vihicleNo : $("#vihicleNo").val(),
                sEndUser : $("#sEndUser").val()
               },
            function(data) {
                //$("#stockOutNoDetail").remove();
                //reSetValidete(); //벨류데이션 초기화
                searchDataMaping(data);    //DATA맵핑 
            });
    }
    
    /* searchData 맵핑 */
    function searchDataMaping(data){
           
        var contents = "";
        var cHeader = "<tr>"
        	+"<th width='25%'>Stock Out No</th>"
        	+"<th width='15%'>Date</th>"
        	+"<th width='40%'>Name</th>"
        	+"<th width='20%'>Tel</th>"
        	+"</tr>";
        if(data.resultList.length == 0){
            contents = "<tr><td colspan='4' height='50' bgcolor='#FFFFFF' align='center'><B>No Data</B></td></tr>";
            $("#stockOutNoDetail").html(cHeader+contents);
                
        }else{
        $.each(data.resultList, function(index){  // List로 받아온값 (여러건)  
           contents += "<tr style='cursor:pointer' onclick='rowSelect(this, \""+this.outNo+"\", \""+this.outInvoice+"\");  '>"
               +"<td align='center'>"+this.outInvoice+"</td>"
               +"<td align='center'>"+this.requestDate+"</td>"
               +"<td align='left' class='boSub'>"+this.custName+"</td>"
               +"<td align='left' class='boSub'>"+this.tel+"</td>"
               +"</tr>";
            
        });
        }
        var totalPage = Math.ceil(parseInt(data.stockOutNoCount)/parseInt(5));        
        $("#spanCount").empty().html("Total : "+data.stockOutNoCount);
        $("#pageCount").empty().html("Page : "+$("#pageNum").val()+" / "+totalPage);                    
        $("#page").empty().html(data.pageSplit);
        
        $("#stockOutNoDetail").html(cHeader+contents);  // 조회 값 뿌리기
    }   

    function ajaxPageSplit(num) {
        $("#pageNum").val(num);
        view(num);
    }

    function rowSelect(obj, outNo, outInvoice){
        $("#outNoTmp").val(outNo);
        $("#outInvoiceTmp").val(outInvoice);
        $("#stockOutNoDetail tr").css("backgroundColor","#FFFFFF");
        obj.style.backgroundColor="#e0eeee";    
        document.ondblclick=dblclick;
    }
    
    function dblclick(){
        $("#confirmBtn").click(); 
    }
    
    /************************************************************************/
    /*                      고객 팝업 버튼 , 리턴값처리                     */
    /************************************************************************/
    var popType ="";
    /* 고객 팝업 버튼 */
    function customerPopCall(obj, type){
        popType = type; 

        if(type == 'M'){
            window.open('/customerPop.html?customer=2', 'customerPop', 'width=415, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
        }else{
            window.open('/customerPop2.html?customer=3', 'customerPop', 'width=415, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
        }
    }
    
    /* 고객정보 맵핑 */
    function customerPopValue(custCode , custName , addr1 , addr2, tel, fax){  
         switch(popType){
         case "S":
               $("#sEndUser").val(custCode);
               $("#sEndUserName").val(custName); 
               break;
         case "M":
             $("#sMessrs").val(custCode);
             $("#sMessrsName").val(custName); 
             break;
         }
           popType = "";
    };
    
    /************************************************************************/
    /*                      상품 팝업 버튼 , 리턴값처리                     */
    /************************************************************************/
    /* 상품 팝업 버튼 */
    function onProductPopup(obj){
        var custCodeTmp = "";
        if($("#roleId").val() == "3"){
            custCodeTmp = $("#custCodeUser").val();
        }
        window.open('/productPop.html?custCode='+custCodeTmp, 'changeProductPop', 'width=615, height=450, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    }

    function productPopValue(goodsCode, goodsName, unit, boxQty, hsCode, productCode, custCode, custName){

        $("#sGoodsCode").val(goodsCode);
        $("#sGoodsName").val(goodsName);   
    }
</script>
</head>
<body>
<div class="wrapP2">
    <div class="pagetitle">
        <h1>STOCK OUT NO</h1>
    </div>
    <div>
        <table class="TableST">
            <tr>
                <th width="15%">End User</th>
                <td width="35%">
                    <input type="text" class="inSTR80" id="sEndUserName" name="sEndUserName" maxlength="20"/>
                    <input type="hidden" id="sEndUser" name="sEndUser" />
                    <img alt="Search" hight="16" width="16" onclick="customerPopCall(this, 'S')" src="/images/web/bkn_zoom.gif">
                </td>
                <th width="15%">Messrs</th>
                <td width="35%">
                    <input type="text" class="inSTR80" id="sMessrsName" name="sMessrsName" maxlength="20"/>
                    <input type="hidden" id="sMessrs" name="sMessrs" />
                    <img alt="Search" hight="16" width="16" onclick="customerPopCall(this, 'M')" src="/images/web/bkn_zoom.gif">
                </td>
            </tr>
            <tr>
                <th width="15%">Goods</th>
                <td width="35%">
                    <input type='text' class='inSTR80' name='sGoodsName' id='sGoodsName'/>
                    <img src='/images/web/bkn_zoom.gif' aligh='right' id='stockOutPop' onclick='onProductPopup(this);'>
                    <input type='hidden' class='inSTR95' name='sGoodsCode' id='sGoodsCode'/>
                </td>
                <th>Batch</th>
                <td>
                    <input type="text" class="inST80" name="lotNo" id="lotNo"/>                    
                </td>
            </tr>
            <tr>
                <th>Vihicle No</th>
                <td>
                    <input type="text" class="inST80" name="vihicleNo" id="vihicleNo"/>
                </td>
                <th>Stock Out No</th>
                <td>
                    <input type="text" class="inST80" name="outInvoice" id="outInvoice"/>
                </td>
            </tr>
            <tr>
                <th width="15%">Start Date</th>
                <td width="35%">
                    <input type="text" class="inSTR50" id="sStartDate" name="sStartDate" maxlength="5" value=""/>
                </td>
                <th width="15%">End Date</th>
                <td width="35%">
                    <input type="text" class="inSTR50" id="sEndDate" name="sEndDate" maxlength="5" value=""/>
                </td>
            </tr>
        </table>
        <div class="bo_btnS">
            <ul class="btnst"><li class="a"><a href="#" id="btnSearch" >SEARCH</a></li></ul>
        </div>
        <br/><br/><br/><br/>
        <ul>
            <li class="totaltext"><span id="spanCount">Total : 0</span></li>
            <li class="pagetext"><span id="pageCount">Page : 1&frasl;1</span></li>
            <li class="bolistW">
                <table class="TableST4" id="stockOutNoDetail">
                    <!-- tr>
                        <th width="140px">STOCK OUT NO</th>
                        <th width="90px">NAME</th>
                        <th width="90px">TEL</th>
                    </tr>
                    <span id="stockOutNoDetail">
                        <tr>
                           <td colspan="9"></td>    
                        </tr>
                    </span-->                    
                </table>
            </li>
        </ul>
    </div>
    <!--<div class="padeNum">
    <a href="#"><img src="images/web/icon_navi_01.gif" /></a>1.2.3.4.5.6.7<a href="#"><img src="images/web/icon_navi_02.gif" /></a>
    </div>
    -->
    <div class="page_wrap">
        <div class="page" id="page" >
        </div>
    </div>
    <div class="bo_btn">
        <ul class="btnst"><li class="a"><a href="#" id="confirmBtn" >CONFIRM</a></li></ul>
        <ul class="btnst"><li class="a"><a href="#" id="cancelBtn" >CANCEL</a></li></ul>
    </div>
    <input type="hidden" name="pageNum" id="pageNum" value="1">
    <input type="hidden" name="outNoTmp" id="outNoTmp"/>
    <input type="hidden" name="outInvoiceTmp" id="outInvoiceTmp"/>
</div>
</body>
</html>